home *** CD-ROM | disk | FTP | other *** search
/ PC Media 4 / PC MEDIA CD04.iso / share / prog / gcoope10 / typing.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-21  |  2.7 KB  |  99 lines

  1.  
  2. /*
  3.  
  4.     EXPERIMENTAL: strong type checking for GCOOPE !!!
  5.  
  6.     July 10, 1994 by Brian Lee Price
  7.  
  8.     Its not exactly elegant but it is usable to some extent.
  9.     Let me know if it is useful to you.
  10.  
  11.  
  12.     if you want to use GCOOPE in a manner compatible with strong
  13.     type checking using the following notations:
  14.  
  15.     (In the following genName is the name of a generic function)
  16.  
  17.     The proto-typedef for genName is genName.
  18.     The genfunc index variable for genName is GFgenName.
  19.  
  20.  
  21.     The definition for the macro PROTO used to create proto-typedefs
  22.     for generic functions with strong type checking:
  23.  
  24. */
  25.  
  26. #define PROTO(returnValue, genFuncName, passedParms) \
  27.     typedef returnValue (* genFuncName)passedParms
  28.  
  29. /*
  30.  
  31.     Suggested declaration style for proto-typedefs:
  32.  
  33. PROTO(void *, testgen, (object, int, char));
  34.  
  35.     where testgen is the name of the generic function, and
  36.     the true prototype for it would be:
  37.  
  38.         void * testgen(object, int, char);
  39.  
  40.  
  41.  
  42.     The following macro is used to call the function dispatcher when
  43.     using strong type checking:
  44.  
  45. */
  46.  
  47. #define G(genFunc) ((genFunc (*)(generic)) g)(GF##genFunc)
  48.  
  49. /*
  50.  
  51.     For the same genFunc function named testFunc, strong vs weak
  52.     dispatcher calls would look like:
  53.  
  54.         ... = G(testFunc) ...      strong type checking
  55.  
  56.         ... = g(GFtestFunc) ...       weak type checking
  57.  
  58.  
  59.     This technique works well in most cases, however for Kill and
  60.     Err it should not be used, they should remain weakly type checked.
  61.     The genFunc New presents a special case.  You may use strong
  62.     type casting with New however you should use the name Newclass
  63.     for your proto-typedef function name where class is the name
  64.     of the class, then use the following macro:
  65.  
  66. */
  67.  
  68. #define NEW(className) \
  69.     ((New##className (*)(generic)) g)(New)
  70.  
  71. /*
  72.  
  73.     Just remember that your passed parameters must still include
  74.     className as the first parameter and it must be of type object.
  75.     The following is a functional example of the necessary
  76.     proto-typedef that declares a prototype for the genfunction
  77.     New with the first parameter Class:
  78.  
  79. PROTO(object, NewClass, (object, int, int,...));
  80.  
  81.  
  82.  
  83.     proto-typedefs may only be declared once, unlike true prototypes,
  84.     duplicate proto-typedefs will cause an error even if exactly the
  85.     same.  Therefore if you intend to use proto-typedefs you should
  86.     maintain a separate header file containing the proto-typedefs
  87.     for all generic functions.
  88.  
  89.  
  90.         If you desire to use strong type checking for a generic
  91.     function whose methods take different types and numbers of
  92.     parameters, you may be able to get away with something like
  93.     that suggested for the genFunc New, however it is doubtful.
  94.     New is a special case because you know what class you will be
  95.     dispatching to, many times you won't be entirely sure.
  96.  
  97. */
  98.  
  99.